package coms.itboyes.bycommon.commonwidget.address;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import coms.itboyes.bycommon.base.BaseDialogFragment;
import coms.itboyes.bycommon.bycommon.R;
import coms.itboyes.bycommon.commonwidget.address.addressview.AddressSelectView;

public class AddressFragment extends BaseDialogFragment implements OnClickListener {


    private AddressSelectView addressSelect;
    GetInforListener getInforListener;
    public interface GetInforListener {
        public void onGetinforListener(String province, String city, String district, String provinceNo, String cityNo, String districtNo);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        View v = inflater.inflate(R.layout.fragment_address2, container, false);
        addressSelect = (AddressSelectView) v.findViewById(R.id.addressselect);
        return v;
    }




//	@Override
//	public void onStart() {
//		super.onStart();
//		final DisplayMetrics dm = new DisplayMetrics();
//		getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
//
//		final WindowManager.LayoutParams layoutParams = getDialog().getWindow()
//				.getAttributes();
//		layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
//		layoutParams.gravity = Gravity.BOTTOM;
//		layoutParams.height=380;
//		getDialog().getWindow().setAttributes(layoutParams);
//	}

    @Override
    public void onClick(View arg0) {
//        int i = arg0.getId();
//        if (i == R.id.btn_confirm) {
            addressSelect.getAddressData();
            String provinceNo = Integer.toString(addressSelect.getProvinceNo());
            String cityNo = Integer.toString(addressSelect.getCityNo());
            String districtNo = Integer.toString(addressSelect.getDistrictNo());
            System.out.println(addressSelect.getProvinceName()+","+addressSelect.getCityName()+","+ addressSelect.getDistrictName());
            GetInforListener listener = (GetInforListener) getActivity();
            listener.onGetinforListener(addressSelect.getProvinceName(), addressSelect.getCityName(), addressSelect.getDistrictName(), provinceNo, cityNo, districtNo);
//        } else if (i == R.id.btn_cancel) {
//            this.dismiss();
//        }


        //添加数据
//		Bundle bundle=new Bundle();
//		bundle.putString("provincename", addressSelect.getProvinceName());
//		bundle.putString("cityname", addressSelect.getCityName());
//		bundle.putString("districtname", addressSelect.getDistrictName());
//		bundle.putString("provinceno", provinceNo);
//		bundle.putString("cityno", cityNo);
//		fragment.setArguments(bundle);
//		FragmentManager fragmentManager = getFragmentManager();
//        //开始Fragment事务
//        FragmentTransaction fTransaction = fragmentManager.beginTransaction();
//        //将Fragment添加到事务中，并指定一个TAG 
//        fTransaction.add(fragment, "123");
//        //提交Fragment事务
//        fTransaction.commit();

        //Toast.makeText(App.ctx, ""+addressSelect.getCityNo()+addressSelect.getDistrictNo(), 0).show();
        this.dismiss();

    }

}
